package com.swim.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="RegisteredUser")
public class RegisteredUser implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9053433552551165684L;

	@Id
	@Column(name="email")
	private String email;
	
	@Column(name="password", nullable=false)
	private String password;
	
	@Column(name="admin", nullable=false)
	private boolean admin;
	
	@Column(name="name", nullable=false)
	private String name;
	
	@Column(name="surname", nullable=false)
	private String surname;
	
	@Column(name="city", nullable=false)
	private String city;
	
	@ManyToMany
	@JoinTable(name = "HasSkill", 
		joinColumns =
			@JoinColumn(name = "email", referencedColumnName = "email"),
		inverseJoinColumns =
			@JoinColumn(name = "idSkill", referencedColumnName = "id")
	)
	private Set<Skill> userSkills;
	
	/**
	 * @return the collaboration recived
	 */
	public Set<Collaboration> getReceivedCollaborations() {
		return receivedCollaborations;
	}

	/**
	 * @param receivedCollaborations the collaboration received to set
	 */
	public void setReceivedCollaborations(Set<Collaboration> receivedCollaborations) {
		this.receivedCollaborations = receivedCollaborations;
	}

	/**
	 * @return the collaboration offered
	 */
	public Set<Collaboration> getOfferedCollaborations() {
		return offeredCollaborations;
	}

	/**
	 * @param offeredCollaborations the collaboration offered to set
	 */
	public void setOfferedCollaborations(Set<Collaboration> offeredCollaborations) {
		this.offeredCollaborations = offeredCollaborations;
	}

	/**
	 * @return the collaboration's request received
	 */
	public Set<CollaborationRequest> getReceivedCollaborationRequests() {
		return receivedCollaborationRequests;
	}

	/**
	 * @param receivedCollaborationRequests the collaboration's request received to set
	 */
	public void setReceivedCollaborationRequests(
			Set<CollaborationRequest> receivedCollaborationRequests) {
		this.receivedCollaborationRequests = receivedCollaborationRequests;
	}

	/**
	 * @return the collaboration's request offered
	 */
	public Set<CollaborationRequest> getSentCollaborationRequests() {
		return sentCollaborationRequests;
	}

	/**
	 * @param sentCollaborationRequests the collaboration's request offered to set
	 */
	public void setSentCollaborationRequests(
			Set<CollaborationRequest> sentCollaborationRequests) {
		this.sentCollaborationRequests = sentCollaborationRequests;
	}

	/**
	 * @return the friendship's request received
	 */
	public Set<FriendshipRequest> getReceivedFriendshipRequests() {
		return receivedFriendshipRequests;
	}

	/**
	 * @param receivedFriendshipRequest the friendship's request received to set
	 */
	public void setReceivedFriendshipRequests(
			Set<FriendshipRequest> receivedFriendshipRequests) {
		this.receivedFriendshipRequests = receivedFriendshipRequests;
	}

	/**
	 * @return the friendship's request offered
	 */
	public Set<FriendshipRequest> getSentFriendshipRequests() {
		return sentFriendshipRequests;
	}

	/**
	 * @param sentFriendshipRequests the friendship's request offered to set
	 */
	public void setSentFriendshipRequests(
			Set<FriendshipRequest> sentFriendshipRequests) {
		this.sentFriendshipRequests = sentFriendshipRequests;
	}

	/**
	 * @return the skill's request received
	 */
	public Set<SkillRequest> getReceivedSkillRequests() {
		return receivedSkillRequests;
	}

	/**
	 * @param receivedSkillRequest the skill's request received to set
	 */
	public void setReceivedSkillRequest(Set<SkillRequest> receivedSkillRequests) {
		this.receivedSkillRequests = receivedSkillRequests;
	}

	/**
	 * @return the skill's request offered
	 */
	public Set<SkillRequest> getSentSkillRequests() {
		return sentSkillRequests;
	}

	/**
	 * @param sentSkillRequest the skill's request offered to set
	 */
	public void setSentSkillRequest(Set<SkillRequest> sentSkillRequests) {
		this.sentSkillRequests = sentSkillRequests;
	}

	/**
	 * @return the serial id
	 */
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	/**
	 * @param userSkills the user's skill to set
	 */
	public void setUserSkills(Set<Skill> userSkills) {
		this.userSkills = userSkills;
	}
	@ManyToMany
	@JoinTable(name = "FriendOf", 
		joinColumns =
			@JoinColumn(name = "email", referencedColumnName = "email"),
		inverseJoinColumns =
			@JoinColumn(name = "email1", referencedColumnName = "email")
	)
	private Set<RegisteredUser> friends;
	
	@ManyToMany(mappedBy="friends")
	private Set<RegisteredUser> friends1;
	
	@ManyToMany
	@JoinTable(name = "Notifications",
		joinColumns = 
			@JoinColumn(name = "email", referencedColumnName = "email"),
		inverseJoinColumns = 
			@JoinColumn(name = "email1", referencedColumnName = "email")
	)
	private Set<RegisteredUser> receivedNotifications;
	
	public Set<RegisteredUser> getSentNotifications() {
		return sentNotifications;
	}

	public void setSentNotifications(Set<RegisteredUser> sentNotifications) {
		this.sentNotifications = sentNotifications;
	}

	public Set<RegisteredUser> getReceivedNotifications() {
		return receivedNotifications;
	}

	public void setReceivedNotifications(
			Set<RegisteredUser> receivedNotifications) {
		this.receivedNotifications = receivedNotifications;
	}

	public void setReceivedSkillRequests(Set<SkillRequest> receivedSkillRequests) {
		this.receivedSkillRequests = receivedSkillRequests;
	}

	public void setSentSkillRequests(Set<SkillRequest> sentSkillRequests) {
		this.sentSkillRequests = sentSkillRequests;
	}
	@ManyToMany(mappedBy="receivedNotifications")
	private Set<RegisteredUser> sentNotifications;
	
	
	@OneToMany(mappedBy = "emailTo")
	private Set<Collaboration> receivedCollaborations;
	
	@OneToMany(mappedBy="emailFrom")
	private Set<Collaboration> offeredCollaborations;
	
	@OneToMany(mappedBy = "emailTo")
	private Set<CollaborationRequest> receivedCollaborationRequests;
	
	@OneToMany(mappedBy="emailFrom")
	private Set<CollaborationRequest> sentCollaborationRequests;
	
	@OneToMany(mappedBy = "emailTo")
	private Set<FriendshipRequest> receivedFriendshipRequests;
	
	@OneToMany(mappedBy="emailFrom")
	private Set<FriendshipRequest> sentFriendshipRequests;
	
	@OneToMany(mappedBy = "emailTo")
	private Set<SkillRequest> receivedSkillRequests;
	
	@OneToMany(mappedBy="emailFrom")
	private Set<SkillRequest> sentSkillRequests;
	
	/**
	 * @return the user's friends
	 */
	public Set<RegisteredUser> getFriends() {
		return this.friends;
	}
	
	/**
	 * @return the friends of the friends????
	 */
	public Set<RegisteredUser> getFriends1() {
		return this.friends1;
	}
	
	/**
	 * @param friends the user's friend to set
	 */
	public void setFriends(Set<RegisteredUser> friends) {
		this.friends = friends;
	}
	
	/**
	 * @param ?
	 */
	public void setFriends1(Set<RegisteredUser> friends1) {
		this.friends = friends1;
	}
	
	public RegisteredUser() {}
	
	/**
	 * @return the user's skill
	 */
	public Set<Skill> getUserSkills() {
		return this.userSkills;
	}
	
	public RegisteredUser(String email, String password, boolean admin, 
			String name, String surname, String city) {
		setEmail(email);
		setPassword(password);
		setAdmin(admin);
		setName(name);
		setSurname(surname);
		setCity(city);
	}
	
	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}
	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the admin
	 */
	public boolean isAdmin() {
		return admin;
	}
	/**
	 * @param admin the admin to set
	 */
	public void setAdmin(boolean admin) {
		this.admin = admin;
	}
	/**
	 * @return the surname
	 */
	public String getSurname() {
		return surname;
	}
	/**
	 * @param surname the surname to set
	 */
	public void setSurname(String surname) {
		this.surname = surname;
	}
	/**
	 * @return the city
	 */
	public String getCity() {
		return city;
	}
	/**
	 * @param city the city to set
	 */
	public void setCity(String city) {
		this.city = city;
	}
	
	@Override
	public boolean equals(Object o) {
		RegisteredUser r = (RegisteredUser)o;
		return email.equals(r.getEmail());
	}
	
}
